package main

func countCharacters(words []string, chars string) int {
	size := 0
	m := make(map[byte]int)
	for i := 0; i < len(chars); i++ {
		m[chars[i]]++
	}

	for i := 0; i < len(words); i++ {
		tM := make(map[byte]int)
		for j := 0; j < len(words[i]); j++ {
			tM[words[i][j]]++
		}
		can := true
		for k, v := range tM {
			count, ok := m[k]
			if !ok || v > count {
				can = false
				break
			}
		}
		if can {
			size++
		}
	}
	return size
}
